import { defineStore } from "pinia";

export const useAPIStore = defineStore("api", {
  state: () => ({
    deviceIP: "localhost",
    rosIP: "localhost",
    // centerIP: '172.16.3.130'
    centerIP: "172.16.3.102",
  }),
  getters: {
    wsUrl: (state) => "ws://" + (state.wsIP || state.deviceIP) + ":8740/",
    rosUrl: (state) => "ws://" + (state.rosIP || state.deviceIP) + ":9090",
    rosImgUrl: (state) =>
      "http://" + (state.rosImgIP || state.rosIP) + ":9091/",
    mapUrl: (state) => "http://" + (state.mapIP || state.centerIP) + ":8720/",
    postureUrl: (state) =>
      "http://" + (state.postureIP || state.centerIP) + ":8721/",
    amrUrl: (state) => "http://" + (state.amrIP || state.deviceIP) + ":8740/",
    centerUrl: (state) =>
      "http://" + (state.centerIP || state.centerIP) + ":8741/",
    taskUrl: (state) => "http://" + (state.taskIP || state.centerIP) + ":8731/",
    orderUrl: state => 'http://' + (state.orderIP || state.centerIP) + ':8730/'
  },
  actions: {
    // 设置配置文件ip
    setIP(data) {
      for (const key in data) {
        this[key] = data[key];
      }
    },
  },
  // 开启数据缓存
  persist: {
    enabled: true,
    strategies: [
      {
        key: "api",
        storage: localStorage,
        paths: ["deviceIP", "rosIP", "centerIP"],
      },
    ],
  },
});
